package com.neusoft.controller;

import java.math.BigDecimal;

import com.neusoft.po.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.po.VirtualWallet;
import com.neusoft.po.VirtualWalletTransaction;
import com.neusoft.service.VirtualWalletService;

@RefreshScope // 开启动态刷新
@RestController
@RequestMapping("/VirtualWalletController")
public class VirtualWalletController {
	@Autowired
	private VirtualWalletService virtualWalletService;

	// 根据用户编号查询虚拟钱包
	@GetMapping("/getVirtualWalletByUserId/{userId}")
	public CommonResult<VirtualWallet> getVirtualWalletByUserId(@PathVariable String userId) {
		return new CommonResult(200, "success", virtualWalletService.getVirtualWalletByUserId(userId));
	}

	// 查询余额
	@GetMapping("/getBalanceByWalletId/{walletId}")
	public CommonResult<BigDecimal> getBalance(@PathVariable Integer walletId) {
		return new CommonResult(200, "success", virtualWalletService.getBalance(walletId));
	}

	// 出账（提现）
	@PostMapping("/FromWalletId/{walletId}/{amount}")
	public CommonResult<Integer> debit(@PathVariable Integer walletId, @PathVariable BigDecimal amount) {
		return new CommonResult(200, "success", virtualWalletService.debit(walletId, amount));
	}

	// 入账（充值）
	@PostMapping("/ToWalletId/{walletId}/{amount}")
	public CommonResult<Integer> credit(@PathVariable Integer walletId, @PathVariable BigDecimal amount) {
		return new CommonResult(200, "success", virtualWalletService.credit(walletId, amount));
	}

	// 转账
	@PostMapping("/Payment/{fromWalletId}/{toWalletId}/{amount}/{orderId}")
	public CommonResult<Integer> transfer(@PathVariable Integer fromWalletId, @PathVariable Integer toWalletId,
			@PathVariable BigDecimal amount, @PathVariable Integer orderId) {
		return new CommonResult(200, "success", virtualWalletService.transfer(fromWalletId, toWalletId, amount, orderId));
	}
}
